package com.example.primomobile;

import java.util.HashMap;

import android.view.DragEvent;
import android.view.View;
import android.view.View.OnDragListener;
import android.widget.ImageView;

import com.example.primomobile.utils.Utils;

class PecasRemoveDragListener implements OnDragListener {
	private ImageAdapter imageAdapter;

	public PecasRemoveDragListener( ImageAdapter imageAdapter ) {
		this.imageAdapter = imageAdapter;
	}

	@Override
	public boolean onDrag( View v, DragEvent event ) {

		switch ( event.getAction() ) {
			case DragEvent.ACTION_DRAG_STARTED:

				break;
			case DragEvent.ACTION_DRAG_ENTERED:
				break;
			case DragEvent.ACTION_DRAG_EXITED:
				break;
			case DragEvent.ACTION_DROP:

				ImageView view = (ImageView) event.getLocalState();
				if ( view.getTag() != null && ( (Boolean) ( (HashMap<String, Object>) view.getTag() ).get( Utils.REMOVE ) ) ) {
					imageAdapter.removeView( view );
					view.setVisibility( View.INVISIBLE );
				}
				break;
			case DragEvent.ACTION_DRAG_ENDED:
			default:
				break;
		}
		return true;
	}
}